package com.mycampus.crawler.bit;

import us.codecraft.webmagic.Page;
import us.codecraft.webmagic.Request;
import us.codecraft.webmagic.Site;
import us.codecraft.webmagic.Spider;
import us.codecraft.webmagic.model.HttpRequestBody;
import us.codecraft.webmagic.processor.PageProcessor;
import us.codecraft.webmagic.utils.HttpConstant;

import java.util.HashMap;
import java.util.Map;

public class BitPageProcessor implements PageProcessor {
    private Site site = Site.me().setRetryTimes(3).setSleepTime(1000).setTimeOut(10000);

    @Override
    public void process(Page page) {
        String s = page.getUrl().get();
        System.out.println(s);

        String rawText = page.getRawText();
        System.out.println(rawText);
    }

    @Override
    public Site getSite() {
        return site;
    }

    public static void main(String[] args) {
        Request request = new Request("https://a.jiuyeb.cn/mobile.php/enrollment/getlist");
        request.setMethod(HttpConstant.Method.POST);
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("school_id", "d591a05a-5900-4b09-9adc-acf1eade380a");
        paramMap.put("login_user_id", 1);
        paramMap.put("login_admin_school_code", "10007");
        paramMap.put("login_admin_school_id", "d591a05a-5900-4b09-9adc-acf1eade380a");
        request.setRequestBody(HttpRequestBody.form(paramMap, "utf-8"));
        request.addHeader("auth", "Baisc MTAyNDY6MTAyNDY=");

        Spider.create(new BitPageProcessor()).addRequest(request).thread(5).run();
    }
}
